
import React from 'react';
import { Provider, useSelector, useDispatch } from 'react-redux';
import List4 from './List4'
import Input4 from './Input4';


const ToDoList = () => {
    const { list } = useSelector((state) => state);
    const List = list.list;
    const dispatch = useDispatch();

    const Add = (e) => {
        if (e.keyCode === 13) {
            dispatch({ type: 'add_item', payload: e.target.value})
        }
    }

    const Del = (i) =>{
        let newList = List.filter((item,index)=>i != index)
        dispatch({type:'del',payload:newList})
    }

    return (
        <div>
            <h1>ToDoList</h1>
            <Input4  add={Add} />
            <List4 del={Del} />
        </div>
    )
}

export default ToDoList;
